/*
 * @Author: weidewei
 * @Date: 2025-10-21 09:51:33
 * @LastEditors: weidewei
 * @LastEditTime: 2025-11-26 16:02:36
 * @Description: 
 * @FilePath: \2025-front-face\vite-react-ts-template\src\router\routes.tsx
 */
import { lazy } from 'react';
import { Navigate } from 'react-router-dom';

import ErrorBoundary from '@/components/errorBoundary';
import LazyImportComponent from '@/components/lazyImportComponent';

import { protectedLoader } from './loader';
import { usersLoader } from './loader';
import { tokenLoader } from './loader';

const routes = [
  {
    path: '/login',
    element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/login'))} />,
  },
  {
    path: '/',
    loader: protectedLoader,
    element: <LazyImportComponent lazyChildren={lazy(() => import('@/layout'))} />,
    errorElement: <ErrorBoundary />,
    children: [
      {
        index: true,
        element: <Navigate to={'/user'} replace={true} />,
      },
      {
        path: '/user',
        loader: usersLoader,
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/user'))} />,
      },
      {
        path: '/manage',
        loader: tokenLoader,
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/manage'))} />,
      },
      {
        path: '/file/:id?',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/file'))} />,
      },
      {
        path: '/info',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/info'))} />,
      },
      {
        path: '/useState',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/useState'))} />,
      },
      {
        path: '/useRef',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/useRef'))} />,
      },
      {
        path: '/useTransition',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/useTransition'))} />,
      },
      {
        path: '/useEffect',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/useEffect'))} />,
      },
      {
        path: '/useContext',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/useContext'))} />,
      },
      {
        path: '/useLayoutEffect',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/useLayoutEffect'))} />,
      },
      {
        path: '/useReducer',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/useReducer'))} />,
      },
      {
        path: '/shopCar',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/shopCar'))} />,
      },
      {
        path: '/useSyncExternalStore',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/useSyncExternalStore'))} />,
      },
      {
        path: '/useDeferredValue',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/useDeferredValue'))} />,
      },
      {
        path: '/useImperativeHandle',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/useImperativeHandle'))} />,
      },
      {
        path: '/memo',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/memo'))} />,
      },
      {
        path: '/useMemo',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/useMemo'))} />,
      },
      {
        path: '/useCallback',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/useCallback'))} />,
      },
      {
        path: '/communication',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/communication'))} />,
      },
      {
        path: '/react-route',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/react-route'))} />,
      },
      {
        path: '/ts-learn',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/ts-learn'))} />,
      },
      {
        path: '/suspense',
        element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/suspense'))} />,
      }
    ],
  },
  {
    path: '*',
    element: <LazyImportComponent lazyChildren={lazy(() => import('@/pages/notFound'))} />,
  },
];

export default routes;
